home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / ScreenSavers / BackSpaceViews / PatchworkView.BackModule / PatchworkView.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  2.9 KB  |  123 lines

  1. //
  2. // PatchworkView.m
  3. //
  4. // Matt Pharr- pharr@cs.yale.edu
  5. //
  6.  
  7. #import "PatchworkView.h"
  8. #import <appkit/appkit.h>
  9. #import <dpsclient/wraps.h>
  10. #import <defaults/defaults.h>
  11. #import <libc.h>
  12. #import <stdlib.h>
  13.  
  14.  
  15. @implementation PatchworkView
  16.  
  17. - oneStep
  18. {
  19.     float red, green, blue;
  20.  
  21.     /* Sure, some boxes will be partially or fully off-screen, but this way, */
  22.     /* the edges of the screen aren't missed most of the time.... */
  23.  
  24.     theBox.origin.x= randBetween(bounds.origin.x - 50, bounds.size.width + 50);
  25.     theBox.origin.y= randBetween(bounds.origin.y - 50, bounds.size.height + 50);
  26.     theBox.size.width= randBetween(0.0, bounds.size.width - theBox.origin.x + 50);
  27.     theBox.size.height= randBetween(0.0, bounds.size.height - theBox.origin.y + 50);
  28.  
  29.     if ([Window defaultDepthLimit] == NX_TwoBitGrayDepth) {
  30.         /* Black And White Machines */
  31.         color= randBetween(0.0, 1.0);
  32.         if ((int)(15 * color) == 1) {            /* This way, solidly black squares */
  33.             color= 0.0;                          /* are more common, just to be totally */
  34.         }                                        /* paranoid about avoiding burn-in */
  35.         PSsetgray(color);
  36.     }
  37.  
  38.     else {                                       /* thanks a bunch to */
  39.         red= randBetween(0.0, 1.0);              /* rob@lighthouse.com for */
  40.         green= randBetween(0.0, 1.0);            /* writing and sending me */
  41.         blue= randBetween(0.0, 1.0);             /* the code to do it in */
  42.         if ((int)(15 * red) == 1) {              /* color on color machines... */
  43.             red= green= blue= 0.0;
  44.         } 
  45.         PSsetrgbcolor(red,green,blue);
  46.     }
  47.  
  48.     PSrotate(randBetween(0.0, 90.0));
  49.     NXRectFill(&theBox);
  50.     
  51.     usleep((10-speed) * 6000);
  52.  
  53.     return self;
  54. }
  55.  
  56.  
  57. - initFrame:(const NXRect *)frameRect
  58. {
  59.     [super initFrame:frameRect];
  60.  
  61.     [self inspector:self];
  62.  
  63.     if (NXGetDefaultValue([NXApp appName], "patchViewSpeed") == NULL) {
  64.         NXWriteDefault([NXApp appName], "patchViewSpeed", "5.0");
  65.         speed= 5.0;
  66.     }
  67.     else
  68.         speed= atof(NXGetDefaultValue([NXApp appName], "patchViewSpeed"));
  69.  
  70.     [theSlider setFloatValue:speed];
  71.     [theSlider update];
  72.     
  73.     return self;
  74. }
  75.  
  76.  
  77. - drawSelf:(const NXRect *)rects :(int)rectCount
  78. {
  79.     if (!rects || !rectCount) {
  80.         return self;
  81.     }
  82.  
  83.     PSsetgray(0.0);
  84.     NXRectFill(rects);
  85.  
  86.     return self;
  87. }
  88.  
  89.  
  90. - (const char *)windowTitle
  91. {
  92.     return "Patchwork";
  93. }
  94.  
  95.  
  96. - inspector:sender
  97. {
  98.     char buf[MAXPATHLEN];
  99.  
  100.     if (!sharedInspectorPanel) {
  101.         sprintf(buf,"%s/%s",[(BSThinker()) moduleDirectory:"Patchwork"],"Patchwork.nib");
  102.         [NXApp loadNibFile:buf owner:self withNames:NO];
  103.     }
  104.  
  105.     return sharedInspectorPanel;
  106. }
  107.  
  108.  
  109. -setSpeed:sender
  110. {
  111.     char temp[20];
  112.     
  113.     speed= [sender floatValue];
  114.     
  115.     sprintf(temp, "%f", speed);
  116.     NXWriteDefault([NXApp appName], "patchViewSpeed", temp);
  117.  
  118.     return self;
  119. }
  120.  
  121. @end
  122.  
  123.